
/*class OuterClass {

    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;

    //实例内部类
    class InnerClass {
        public int data1 = 111;
        public int data4 = 4;
        public static final int data5 = 5;//编译的时候就确认
        private int data6 = 6;

        public void test() {
            System.out.println("这是实例内部类InnerClass::test()" + data5);//"InnerClass::test()" + 5

            //如果外部类和实例内部类中具有相同名称成员时，优先访问的是内部类自己的
            System.out.println(data1);
            System.out.println(this.data1);
            //如果要访问外部类同名成员时候，必须：外部类名称.this.同名成员名字
            System.out.println(OuterClass.this.data1);
            System.out.println(data2);
            System.out.println(data3);

            //在实例内部类中可以直接访问外部类中：任意访问限定符修饰的成员
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println("=====================================");
        }
    }
    public void test() {
        System.out.println("这是外部类OuterClass::test()");
        // 要访问实例内部类中成员，必须要创建实例内部类的对象
        InnerClass innerClass = new InnerClass();
        System.out.println(data1);
        System.out.println(innerClass.data1);
        System.out.println(data2);
        System.out.println(data3);
        System.out.println(innerClass.data4);
        System.out.println(innerClass.data5);
        System.out.println(innerClass.data6);
    }
}*/


/*class OuterClass {
    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;


    //静态内部类：被static修饰的成员内部类
    static class InnerClass {
        public int data4 = 4;
        public static int data5 = 5;
        private int data6 = 6;

        public void test() {
            System.out.println("这是静态内部类InnerClass::test()");
            // 在内部类中只能访问外部类的静态成员，不能直接访问外部类普通成员
            // 静态内部类对象创建 & 成员访问
            OuterClass outerClass = new OuterClass();
            System.out.println(outerClass.data1);
            System.out.println(data2);
            System.out.println(outerClass.data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
    public void test() {
        System.out.println("这是外部类InnerClass::test()");
    }
}*/



class OuterClass {
    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;

    public void func() {
        int data4 = 4;

        //局部内部类：定义在方法体内部
        //不能被public、static等访问修饰限定符修饰
        class InnerClass {
            int data5 = 5;

            public void test() {
                System.out.println(data1);
                System.out.println(data2);
                System.out.println(data3);
                System.out.println(data4);
                System.out.println(data5);
            }
        }
        //只能在该方法体内使用，其他位置都不能用
        InnerClass innerClass = new InnerClass();
        innerClass.test();
        System.out.println(innerClass.data5);
    }
}



interface IA {
    void test();
}

public class Test2 {
    public static void main(String[] args) {
        //new IA();//编译错误，因为是接口，不能被实例化

        //匿名内部类
        IA a = new IA() {
            @Override
            public void test() {
                System.out.println("这是重写了接口的方法！");
            }
        };
        a.test();
    }



    public static void main3(String[] args) {
        OuterClass outerClass = new OuterClass();
        outerClass.func();
    }


    /*public static void main2(String[] args) {
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass();

        innerClass.test();

    }*/



    /*public static void main1(String[] args) {
        OuterClass outerClass = new OuterClass();
        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
        //OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();

        innerClass.test();
        outerClass.test();
    }*/
}